package com.itheima.reggie.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.reggie.common.R;
import com.itheima.reggie.common.dto.OrderPageDTO;
import com.itheima.reggie.entity.OrderDetail;
import com.itheima.reggie.entity.Orders;
import com.itheima.reggie.entity.User;
import com.itheima.reggie.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * 订单
 */
@Slf4j
@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderService orderService;

    @PostMapping("/submit")
    public R<String> payment(@RequestBody Orders orders) {
        return orderService.payment(orders);
    }

    @GetMapping("/userPage")
    public R<Page<OrderPageDTO>> userPage(Long page, Long pageSize) {
        return orderService.userPage(page, pageSize);
    }

    @GetMapping("/page")
    public R<Page<Orders>> orderPage(Long page, Long pageSize, String number, @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date beginTime, @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date endTime) {
        return orderService.orderPage(page, pageSize, number, beginTime, endTime);
    }
}